<?php
/*由bean脚本生成 powerBy--joe*/
namespace app\common\manage;
use app\common\validate\UserVipValidate;
use app\common\model\UserVipModel;
use app\common\bean\UserVipBean;
use app\common\bean\ListMap;
use app\common\utils\TimeUtil;
use app\common\exception\MyException;
use Exception;
class UserVipManage extends BaseManage
{
	/**
	* @return UserVipManage
	*/
	static function getInstance(){
		return parent::getInstance();
	}

	
	/**
	 * @desc 获取分页数据
	 * @param ListMap $listMap
	 * @return ListMap $listMap
	 * @throws Exception
	**/
	public function getPaginatorList(ListMap $listMap) {
		$conditionMap = new ListMap();
		if($timeArray = TimeUtil::getInstance()->dealBetweenTime($listMap)){
            $conditionMap->setParameter(UserVipBean::$createdAt,$timeArray);
        }
		$conditionMap->setAlias(UserVipBean::$alias);
		$listMap->setField(UserVipBean::$alias.ALL_FIELD);
		!$this->getParamBool($listMap,"orderFieldName") ?: $conditionMap->setOrder($listMap->getParameter('orderFieldName').SPACE.$listMap->getParameter('orderType'));
		$conditionMap->setWith('user');
		$resultMap = UserVipModel::getInstance()->getList($conditionMap);
		$resultMap?:MyException::throwMyException("查询数据失败");
		return $resultMap;
	}
	
	/**
	 * @desc 添加数据
	 * @param UserVipBean $userVipBean
	 * @return int int
	 * @throws Exception
	**/
	public function add($userVipBean) {
		UserVipValidate::getInstance()->goCheck(UserVipValidate::$add,$userVipBean->getData());
		// Todo:添加业务处理代码...


		$userVipBean->setCreatedAt(TimeUtil::getInstance()->getTimeNow());
		$result = UserVipModel::getInstance()->addDataGetInsertId($userVipBean->getData());
		$result ?: MyException::throwMyException("插入数据失败");
		return $result;
	}
	
	/**
	 * @desc 编辑数据
	 * @param UserVipBean $userVipBean
	 * @return int int
	 * @throws Exception
	**/
	public function edit($userVipBean) {
		UserVipValidate::getInstance()->goCheck(UserVipValidate::$edit,$userVipBean->getData());
		// Todo:添加业务处理代码...


		$result = UserVipModel::getInstance()->updatedData([UserVipBean::$id => $userVipBean->getId()],$userVipBean->getData());
		$result ?: MyException::throwMyException("更新失败");
		return $result;
	}
	
	/**
	 * @desc 删除数据
	 * @param UserVipBean $userVipBean
	 * @return int int
	 * @throws Exception
	**/
	public function delete($userVipBean) {
		UserVipValidate::getInstance()->goCheck(UserVipValidate::$pkId,$userVipBean->getData());
		// Todo:添加业务处理代码...


		$result = UserVipModel::getInstance()->deleteData([UserVipBean::$id => $userVipBean->getId()]);
		$result ?: MyException::throwMyException("删除失败");
		return $result;
	}
	
	/**
	 * @desc 根据主建获取数据
	 * @param UserVipBean $userVipBean
	 * @return UserVipBean $userVipBean
	 * @throws Exception
	**/
	public function getInfo($userVipBean) {
		UserVipValidate::getInstance()->goCheck(UserVipValidate::$pkId,$userVipBean->getData());
		// Todo:添加业务处理代码...


		$result = UserVipModel::getInstance()->selectData([UserVipBean::$id => $userVipBean->getId()]);
		$result ?: MyException::throwMyException("获取信息失败");
		$userVipBean->setData($result);
		return $userVipBean;
	}
}
